﻿@model DLMemberPointMS.Entity.POCOModel.MemCards
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="~/layui/css/layui.css" />
    <script src="~/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="~/layui/jquery-3.4.1.js" type="text/javascript" charset="utf-8"></script>
    <title>会员等级管理</title>
    <style type="text/css">
        .layui-input {
            margin-top: 5px;
            height: 30px
        }

        .layui-form-label {
            width: auto;
            padding: 5px 10px;
            margin-top: 5px;
        }
    </style>
</head>
<body>
    <div>

        @using (@Html.BeginForm("", "", FormMethod.Post, new { @class = "layui-form", id = "form" }))
        {<div class="layui-form-item">
                <label class="layui-form-label">会员卡号</label>
                <div class="layui-input-inline">
                    <input type="text" name="MC_CardID" lay-verify="title" autocomplete="off" class="layui-input" id="MC_CardID">
                </div>
                <label class="layui-form-label">会员姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="MC_Name" lay-verify="title" autocomplete="off" class="layui-input" id="MC_Name">
                </div>
                <label class="layui-form-label">手机号码</label>
                <div class="layui-input-inline">
                    <input type="text" name="MC_Mobile" lay-verify="title" autocomplete="off" class="layui-input" id="MC_Mobile">
                </div>
                <label class="layui-form-label">会员等级</label>
                <div class="layui-input-inline">
                    @*<input type="text" name="CL_ID" lay-verify="title" autocomplete="off" class="layui-input" id="CL_ID">*@
                    @Html.DropDownList("levels", (ViewData["levels"]) as IEnumerable<SelectListItem>, new { id = "levels" })
                </div>
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    @*<input type="text" name="MC_State" lay-verify="title" autocomplete="off" class="layui-input" id="MC_State">*@
                    @Html.DropDownList("state", (ViewData["state"]) as IEnumerable<SelectListItem>, new { id = "state" })
                </div>
                <button id="searh" type="button" class="layui-btn layui-btn layui-btn-sm" style="margin-top: 5px;"><i class="layui-icon">&#xe615;搜索</i></button>
            </div>

        }
        <table class="layui-inline" lay-filter="table" id="cardList"></table>

    </div>


    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script type="text/html" id="toolsBar">
        <div class="layui-btn-container">
            @*<button class="layui-btn layui-btn-sm" lay-event="add">添加</button>*@
            <button type="button" id="new" class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe654;新增</i></button>
            <button type="button" class="layui-btn layui-btn-sm" lay-event="del"><i class="layui-icon">&#xe640;删除</i></button>
            <button type="button" class="layui-btn layui-btn-sm" lay-event="lock"><i class="layui-icon">&#xe673;挂失/锁定</i></button>
            <button type="button" class="layui-btn layui-btn-sm" lay-event="transfer"><i class="layui-icon">&#xe702;会员转账</i></button>
            <button type="button" class="layui-btn layui-btn-sm" lay-event="change"><i class="layui-icon">&#xe674;会员换卡</i></button>
            <button type="button" class="layui-btn layui-btn-sm" lay-event="export"><i class="layui-icon">&#xe681;导出Excel</i></button>
            <button type="button" id="import" class="layui-btn layui-btn-sm" lay-event="import"><i class="layui-icon">&#xe601;导入Excel</i></button>
        </div>
    </script>
    <script>

        layui.use(['table', 'layer', 'laytpl', 'upload'], function () {
            var table = layui.table,
                layer = layui.layer,
                upload = layui.upload,
                laytpl = layui.laytpl;

            //行内工具栏
            table.on('tool(table)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('您确定删除卡号为' + data.MC_CardID + '的会员吗', function (index) {
                        $.ajax({
                            type: "post",
                            url: "/Member/DeleteMemberResult",
                            data: { "id": data.MC_CardID },
                            success: function (data) {
                                if (data.code == 0) {
                                    layer.msg(data.msg, { icon: 1 })
                                    obj.del();
                                } else {
                                    layer.msg(data.msg, { icon: 2 })
                                }
                            },
                            error: function (data) {
                                layer.msg('删除失败', { icon: 2 })
                            }
                        })
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    // window.location.href='update.aspx?id=' + data.U_ID
                    //layer.alert('编辑行：<br>' + JSON.stringify(data))
                    var id = data.MC_CardID;
                    layer.open({
                        type: 2,
                        content: ['/Member/EditMember/' + id + '', 'no'],
                        area: ['800px', '550px'],
                        offset: ['100px', '400px'],
                        skin: 'layui-layer-molv',
                        maxmin: true,
                        id: 'add',
                        end: function () { table.reload('cardList') }
                    });
                }
            });
            //添加按钮点击事件

            //搜索按钮的点击事件
            $('#searh').on('click', function () {
                //获取输入框的值
                var MemCardsModel = $('#form').serializeArray();
                // var a = JSON.parse(MemCardsModel)
                //var c=  $.parseJSON( MemCardsModel )
                //var b=  JSON.stringify(MemCardsModel)
                // var d = JSON.stringify(MemCardsModel);
                // var e=$.parseJSON( MemCardsModel )
                var MC_CardID = $('#MC_CardID').val();
                var MC_Name = $('#MC_Name').val();
                var MC_Mobile = $('#MC_Mobile').val();
                var CL_ID = $('#levels').val()
                var MC_State = $('#state').val();

                //表格重载，并传回服务器参数
                table.reload('cardList', {
                    //提交方式 Post
                    method: 'post',
                    //传回服务器的参数
                    where: {
                        MC_CardID: MC_CardID,
                        MC_Name: MC_Name,
                        MC_Mobile: MC_Mobile,
                        CL_ID: CL_ID,
                        MC_State: MC_State
                    }
                });
            })

            //转换日期方法
            function FormatToDate(val) {
                if (val != null) {
                    var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
                    //月份为0-11，所以+1，月份小于10时补个0
                    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                    return date.getFullYear() + "-" + month + "-" + currentDate;
                }
                return "";
            }

            //载入表格
            table.render({
                elem: '#cardList',
                url: '/Member/MemcardListResult',
                //开启分页
                page: 'true',
                toolbar: '#toolsBar',
                defaultToolbar: ['filter', 'print', 'exports'],
                cols: [
                    [{
                        type: 'radio'
                    }, {
                        field: 'MC_CardID',
                        width: 150,
                        title: '会员卡号',
                        sort: true
                    },
                    {
                        field: 'MC_Name',
                        width: 150,
                        title: '会员姓名',
                        sort: true
                    },
                    {
                        field: 'MC_Mobile',
                        width: 150,
                        title: '手机号码',
                        sort: true
                    },
                    {
                        field: 'MC_Money',
                        width: 150,
                        title: '卡片余额',
                        sort: true
                    },
                    {
                        field: 'MC_TotalMoney',
                        width: 150,
                        title: '累计消费',
                        sort: true
                    },
                    {
                        field: 'MC_State',
                        width: 150,
                        title: '会员卡状态',
                        sort: true,
                        templet: function (d) {
                            if (d.MC_State == 1) {
                                return "正常"
                            } else if (d.MC_State == 2) {
                                return "挂失"
                            } else if (d.MC_State == 3) {
                                return "锁定"
                            } else {
                                return "未知"
                            }
                        }
                    }, {
                        field: 'MC_Point',
                        width: 150,
                        title: '当前积分',
                        sort: true,
                    }, {
                        field: 'MC_Sex',
                        width: 70,
                        title: '性别',
                        sort: true,
                        templet: function (d) {
                            if (d.MC_Sex == 1) {
                                return "男"
                            } else {
                                return "女"
                            }
                        }
                    }, {
                        field: 'MC_CreateTime',
                        width: 150,
                        title: '登记时间',
                        sort: true,
                        templet: function (d) { return FormatToDate(d.MC_CreateTime) }
                    }, {
                        field: 'CL_LevelName',
                        width: 150,
                        title: '当前等级',
                        sort: true,
                    },
                    {
                        width: 120,
                        title: '操作',
                        sort: true,
                        toolbar: '#barDemo'
                    }
                    ]
                ]
            });
            //上传Excel
            var uploadInst = upload.render({
                elem: '#import', //绑定元素
                url: '/Member/GetUploadUrl',//上传接口
                accept: 'file',
                //exts: 'xls|xlsx',
                done: function (res) {
                    layer.msg('ok')
                    //上传完毕回调
                },
                error: function () {
                    layer.msg('err')
                    //请求异常回调
                }
            });
            //监听事件
            table.on('toolbar(table)', function (obj) {

                //获取所选中对象
                var checkData = table.checkStatus(obj.config.id).data;
                switch (obj.event) {
                    case 'add':
                        layer.open({
                            type: 2,
                            content: ['/Member/EditMember', 'no'],
                            //content: ['/Member/Add', 'no'],
                            area: ['750px', '550px'],
                            offset: ['100px', '400px'],
                            skin: 'layui-layer-molv',
                            maxmin: true,
                            id: 'add',
                            end: function () { table.reload('cardList') }
                        });
                        break;
                    case 'del':
                        if (checkData[0] != null) {
                            var MC_CardID = checkData[0].MC_CardID;
                        } else {
                            layer.msg('请选择一行数据', { icon: 7 })
                            return
                        }
                        layer.confirm('您确定删除卡号为' + MC_CardID + '的会员吗', function (index) {
                            $.ajax({
                                type: 'post',
                                url: '/Member/DeleteMemberResult',
                                data: { "id": MC_CardID },
                                success: function (data) {
                                    if (data.code == 0) {
                                        layer.msg(data.msg, { icon: 1 })
                                        table.reload('cardList')
                                        obj.config.id.del();
                                    } else {
                                        layer.msg(data.msg, { icon: 7 })
                                    }
                                },
                                error: function (data) {
                                    layer.msg('删除失败', { icon: 2 })
                                }
                            })

                        });
                        break;
                    case 'lock':
                        if (checkData[0] != null) {
                            var MC_CardID = checkData[0].MC_CardID;
                        } else {
                            layer.msg('请选择一行数据', { icon: 7 })
                            return
                        }
                        layer.open({
                            type: 2,
                            content: ['/Member/ChangeState/' + MC_CardID, 'no'],
                            //content: ['/Member/Add', 'no'],
                            area: ['500px', '400px'],
                            offset: ['100px', '400px'],
                            skin: 'layui-layer-molv',
                            maxmin: true,
                            id: 'lock',
                            end: function () { table.reload('cardList') }
                        });
                        break;
                    case 'transfer':
                        if (checkData[0] != null) {
                            var MC_CardID = checkData[0].MC_CardID;
                        } else {
                            layer.msg('请选择一行数据', { icon: 7 })
                            return
                        }
                        layer.open({
                            type: 2,
                            content: ['/Member/MemTransfer/' + MC_CardID, 'no'],
                            //content: ['/Member/Add', 'no'],
                            area: ['600px', '620px'],
                            offset: ['100px', '400px'],
                            skin: 'layui-layer-molv',
                            maxmin: true,
                            id: 'lock',
                            end: function () { table.reload('cardList') }
                        });
                        break;
                    case 'change':
                        if (checkData[0] != null) {
                            var MC_CardID = checkData[0].MC_CardID;
                        } else {
                            layer.msg('请选择一行数据', { icon: 7 })
                            return
                        }
                        layer.open({
                            type: 2,
                            content: ['/Member/ChangeCard/' + MC_CardID, 'no'],
                            //content: ['/Member/Add', 'no'],
                            area: ['600px', '620px'],
                            offset: ['100px', '400px'],
                            skin: 'layui-layer-molv',
                            maxmin: true,
                            id: 'lock',
                            end: function () { table.reload('cardList') }
                        });
                        break;
                    case 'export':
                        $.ajax({
                            url: '/Member/ExportResult',
                            type: 'post',
                            success: function (data) {
                                if (data.code == 0) {
                                    layer.msg(data.msg, { icon: 1 })
                                } else {
                                    layer.msg('失败了！请重试', { icon: 2 })
                                }
                            },
                            error: function (data) {
                                layer.msg('失败了！请重试', { icon: 2 })
                            }
                        })
                        break;
                    case 'import':

                        break;
                };
            });
        })



    </script>
</body>
</html>
